package com.tenbent.product.base.enums.base;

import com.tenbent.product.base.utils.EnumUtil;

import java.util.LinkedList;
import java.util.List;

public abstract class SystemEnum {

	private static List<SystemEnum> values = new LinkedList<>();

	public static void register(SystemEnum systemEnum) {
		values.add(systemEnum);
	}

	public static void register(String columnName, Class<BaseEnum> clazz) {
		register(new SystemEnum(columnName) {
			@Override
			public BaseEnum getEnum(int value) {
				return EnumUtil.getByValue(clazz, value);
			}
		});
	}

	private String columnName;

	public SystemEnum(String columnName) {
		this.columnName = columnName;
	}

	public static SystemEnum get(String columnName) {
		for (SystemEnum type : SystemEnum.values) {
			if (type.getColumnName().equals(columnName)) {
				return type;
			}
		}
		return null;
	}

	public String getColumnName() {
		return columnName;
	}

	public BaseEnum getDefault() {
		return null;
	}

	public abstract BaseEnum getEnum(int value);

}
